Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(profiling): move flamegraph and differential flamegraph #30910

Merged
merged 10 commits into from
Jan 14, 2022

Conversation

JonasBa
Copy link
Member

@JonasBa JonasBa commented Jan 4, 2022

Port over the main flamegraph and differential flamegraph classes.

The two classes are used to build (not rendering) the flamegraph in different ways (see buildCallOrderGraph and buildLeftHeavyGraph). They are mainly responsible for outputting an array of frames to render and giving us a configuration view (usually at x:0, y:0, width: timeline duration, height: max stack height).

There are two main functions to look at - buildLeftHeavyGraph and buildCallOrderGraph.
They both iterate over all frames of a profile and append the frames to render to this.frames with the slight difference that buildLeftHeavyGraph sorts the tree first (depth first) and updates the frames startTime and endTime based on their new positions so that startTime is the sum of all child frames preceding the current frame.

e.g. left heavy timings change CleanShot 2022-01-13 at 10 19 28@2x

Note that the order of this.frames doesn't matter and it will be up to whoever consumes the flamegraph to determine what and when to render.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 13, 2022

size-limit report

Path Base Size (ddac3a7) Current Size Change
src/sentry/static/sentry/dist/entrypoints/app.js 53.55 KB 53.56 KB +0.02% 🔺
src/sentry/static/sentry/dist/entrypoints/sentry.css 68.34 KB 68.34 KB 0%

@JonasBa JonasBa requested a review from Zylphrex January 13, 2022 09:00
const counts = new Map<string, number>();

for (const frame of frames) {
const key = frame.frame.name + (frame.frame.file ? frame.frame.file : '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a method on Frame?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zylphrex I thought about it before, but I haven't done it. The reason for that is that this is more the key that we use for color encoding which is not something that the Frame has to know or care about. Maybe a utility fn would be a good middle ground here, wdyt?

this.configSpace = new Rect(0, 0, this.duration, this.depth);
} else {
// If we have no frames, set the trace duration to 1 second so that we can render a placeholder grid
this.configSpace = new Rect(0, 0, 1_000_000, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the units always going to be microseconds? I see that it's possible to specify a unit in Profile. Should that be used to compute this value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah correct, we need to set that too, I missed that 🙏🏼

@JonasBa JonasBa force-pushed the jb/profiling/flamegraph-frame branch from b179054 to 24788b6 Compare January 14, 2022 08:50
@JonasBa JonasBa merged commit 1889fbb into master Jan 14, 2022
@JonasBa JonasBa deleted the jb/profiling/flamegraph-frame branch January 14, 2022 09:25
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants